package com.sky.controller.admin;

import com.sky.constant.RedisConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@Api(tags = "店铺接口")
@RestController
@RequestMapping("/admin/shop")
public class ShopController {

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    /**
     * 设置店铺的营业状态
     * */
    @ApiOperation("设置店铺的营业状态")
    @PutMapping("{status}")
    public Result status(@PathVariable String status){
        stringRedisTemplate.opsForValue().set(RedisConstant.SHOP_STATUS, status);
        return Result.success();
    }
    /**
     * 获取店铺的营业状态
     * */
    @ApiOperation("获取店铺的营业状态")
    @GetMapping("/status")
    public Result<Integer> getStatus(){
        String status = stringRedisTemplate.opsForValue().get(RedisConstant.SHOP_STATUS);
        if(StringUtils.hasLength(status)){
            // 如果redis中有值
            return Result.success(Integer.parseInt(status));
        }else{
            // 如果redis中没有值，返回默认值
            return Result.success(1);
        }
    }
}
